// 当前年月日
export function getNowDate() {
  const date = new Date();
  const y = date.getFullYear();
  let m = date.getMonth() + 1;
  const d = date.getDate();
  m = m < 10 ? "0" + m : m;
  return y + "-" + m + "-" + d + " ";
}

export function DownExcelItem(downloadToken, uploadFileName) {
    
  const a = document.createElement("a");
  a.download = uploadFileName;
  let downloadUrl = "/file/file/report/" + downloadToken;
  a.href = downloadUrl;
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
}

// 前后文字对比，不同显示高亮

export function changColor(logData, beforeData) {
  if (logData != beforeData) {
    return "changeColor";
  } else {
    return "nochange";
  }
}

// 前后图片对比，不同显示高亮
export function imgchangColor(logData, beforeData) {
  if (logData != beforeData) {
    return "changeImg";
  } else {
    return "nochange";
  }
}


// 分转化为元 - 正则解决精度
export const regFenToYuan = (fen) =>{
  var num = fen;
  num=fen*0.01;
  num+='';
  var reg = num.indexOf('.') >-1 ? /(d{1,3})(?=(?:d{3})+.)/g : /(d{1,3})(?=(?:d{3})+$)/g;
  num=num.replace(reg,'$1');
  num = toDecimal2(num)
  return num
}

// 强制保留两位小数
export const toDecimal2 = (x) => {
  var f = parseFloat(x);
  if (isNaN(f)) {
    return false;
  }
  var f = Math.round(x * 100) / 100;
  var s = f.toString();
  var rs = s.indexOf('.');
  if (rs < 0) {
    rs = s.length;
    s += '.';
  }
  while (s.length <= rs + 2) {
    s += '0';
  }
  return s;
}
